<?php
include_once "DBCORE.cls.php";
	class db_order
	{
		private $tablename="tbloders";
		private $db;
		public function __construct()
		{
			$this->db= new DBCORE();
			$this->db->db_connect('localhost','root','','restaurant');
			$this->db->db_query("SET NAMES 'UTF8'");
		}
		//
		
		public function select($id)
		{
			$id = !Empty($id) ? " WHERE OrderID='{$id}'": "";
			$myStrSQL = "SELECT * FROM {$this->tablename} {$id}";
			$data = $this->db->db_fetch_assoc($this->db->db_query($myStrSQL));
			return $data;
		}
		//
		public function selectAll($id)
		{
			if(empty($id))
				return false;
			$myStrSQL="SELECT * FROM {$this->tablename} WHERE RestaurantID ='$id'";
			$result=$this->db->db_query($myStrSQL);
			$resArray = array();
			while ($row = $this->db->db_fetch_assoc($result)) {
				$resArray[] = $row;
			}
			return $resArray;
		}
		//
		public function delete($id)
		{
			$id = !Empty($id) ? " WHERE OrderID='{$id}'": "";
			$myStrSQL="DELETE FROM {$this->tablename} {$id}";
			$this->db->db_query($myStrSQL);
			return $this->db->db_affected_rows();
		}
		public function deleteAll()
		{
			$myStrSQL="DELETE FROM {$this->tablename} WHERE 1";
			$this->db->db_query($myStrSQL);
			return $this->db->db_affected_rows();
		}
		
		
		public function insert(array $data)
		{
			/*$id = isset($data['OrderID'])?$data['OrderID']:"";
			if(!$this->checkExists($id))
				return false;*/
			
			$OrderID = $data['OrderID'];
			$RestaurantID = $data['RestaurantID'];
			$UnitPrice = '0';//isset($data['UnitPrice']?$data['UnitPrice']:"");
			$TimeCreate = $this->db->db_query("SELECT NOW()");
			$TimePaying = $data['TimePaying'];
			$Discount = '0';//isset($data['Discount']?$data['Discount']:"");			
			$PhoneNumber = $data['PhoneNumber'];
			$PhoneID = $data['PhoneID'];
			$EmailContact = $data['EmailContact'];
			$Status = 0;//$data['Status'];
			$myStrSQL = "INSERT INTO {$this->tablename} VALUES ('$OrderID','$RestaurantID','$UnitPrice','$TimeCreate','$TimePaying','$Discount','$PhoneNumber','$PhoneID','$EmailContact','$Status')";						
			$this->db->db_query($myStrSQL);
			if($this->db->db_affected_rows()>0)
				return $this->db->db_insert_id;
			return false;			
		}
		
		//
		
	}
?>